package utils;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 实现请求转发的工具类
 */
public class DispatcherUtils {
    /**
     * 实现页面的跳转
     * @param weburl
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public static void openweb(String weburl, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        RequestDispatcher rd = request.getRequestDispatcher(weburl);
        rd.forward(request,response);
    }

    /**
     *
     * @param errMsg
     * @param backUrl
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public static void openErrWeb(String errMsg,String backUrl,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("errMsg",errMsg);
        request.setAttribute("backUrl",backUrl);
        RequestDispatcher rd = request.getRequestDispatcher("errors.jsp");
        rd.forward(request,response);
    }
}


